package robotCross;

import java.awt.*;
import java.awt.event.InputEvent;

import abbot.Log;
import abbot.tester.AWTConstants;
import abbot.tester.Robot;

public class CrossRobot extends Robot {
	public void click(int mask) {
		click(mask,1);
	}
	public void click(int mask,int count) {
		Log.debug("" + (count > 1 ? (" count=" + count) : ""));
		int keyModifiers = mask & ~AWTConstants.BUTTON_MASK;
		mask &= AWTConstants.BUTTON_MASK;
		setModifiers(keyModifiers, true);
		// Adjust the auto-delay to ensure we actually get a multiple click
		// In general clicks have to be less than 200ms apart, although the
		// actual setting is not readable by java that I'm aware of.
		int oldDelay = getAutoDelay();
		if (count > 1 && oldDelay * 2 > 200) {
			setAutoDelay(0);
		}
		long last = System.currentTimeMillis();
		mousePress(mask);
		while (count-- > 1) {
			mouseRelease(mask);
			long delta = System.currentTimeMillis() - last;
			if (delta > AWTConstants.MULTI_CLICK_INTERVAL)
				Log.warn("Unexpected delay in multi-click: " + delta);
			last = System.currentTimeMillis();
			mousePress(mask);
		}
		setAutoDelay(oldDelay);
		mouseRelease(mask);
		setModifiers(keyModifiers, false);
	}

	public void doubleClick(){
		this.click(InputEvent.BUTTON1_MASK,2);
	 }
	public void clickRightMouse() {
		this.click(InputEvent.BUTTON3_MASK);
	}
	public void clickLeftMouse() {
		this.click(InputEvent.BUTTON1_MASK);
	}
	public void mouseWheel(int wheelAmt){
		try {
			new java.awt.Robot().mouseWheel(wheelAmt);
		} catch (AWTException e) {
			e.printStackTrace();
		}
	}

}
